package com.bh.web.controller.extend;

import com.bh.common.annotation.Log;
import com.bh.common.constant.UserConstants;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.core.page.TableDataInfo;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.SecurityUtils;
import com.bh.common.utils.poi.ExcelUtil;
import com.bh.extend.domain.JcLedEvaluation;
import com.bh.extend.service.IJcLedEvaluationService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 订单评价Controller
 * 
 * @author slx
 * @date 2023-06-15
 */
@RestController
@RequestMapping("/extend/evaluation")
public class JcLedEvaluationController extends BaseController
{
    @Autowired
    private IJcLedEvaluationService jcLedEvaluationService;

    /**
     * 查询订单评价列表
     */
    @ApiOperation("查询订单评价列表")
    @PreAuthorize("@ss.hasPermi('extend:evaluation:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcLedEvaluation jcLedEvaluation)
    {
        startPage();
        List<JcLedEvaluation> list = jcLedEvaluationService.selectJcLedEvaluationList(jcLedEvaluation);
        return getDataTable(list);
    }

    /**
     * 导出订单评价列表
     */
    @PreAuthorize("@ss.hasPermi('extend:evaluation:export')")
    @Log(title = "订单评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcLedEvaluation jcLedEvaluation)
    {
        List<JcLedEvaluation> list = jcLedEvaluationService.selectJcLedEvaluationList(jcLedEvaluation);
        ExcelUtil<JcLedEvaluation> util = new ExcelUtil<JcLedEvaluation>(JcLedEvaluation.class);
        util.exportExcel(response, list, "订单评价数据");
    }

    /**
     * 获取订单评价详细信息
     */
    @ApiOperation("获取订单评价详细信息")
    @PreAuthorize("@ss.hasPermi('extend:evaluation:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jcLedEvaluationService.selectJcLedEvaluationById(id));
    }

    /**
     * 修改订单评价
     */
    @ApiOperation("处置订单评价")
    @PreAuthorize("@ss.hasPermi('extend:evaluation:edit')")
    @Log(title = "订单评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcLedEvaluation jcLedEvaluation)
    {
        jcLedEvaluation.setBadStatus(UserConstants.YES);
        jcLedEvaluation.setBadHandleTime(new Date());
        jcLedEvaluation.setBadHandlePerson(SecurityUtils.getUserId().toString());
        return toAjax(jcLedEvaluationService.updateJcLedEvaluation(jcLedEvaluation));
    }
}
